package crudfx.navigation;
import javax.swing.*;
import java.awt.event.*;
/**
 * @profile desktop
 * @author Sergey Surikov
 */
public class MenuCheck extends MenuPad{
    public var text:String on replace {menuItem.setText(text);};
    public var checked:Boolean=false on replace oldValue=newValue{
        if(not lock)menuItem.setState(newValue);
        };
    var menuItem:JCheckBoxMenuItem;
    var lock:Boolean=false;
    override public function addPopUp(popup:JPopupMenu):Void{popup.add(menuItem);}
    override public function addMenu(menu:JMenu):Void{menu.add(menuItem);}
    init{
        menuItem=new JCheckBoxMenuItem(text,checked);
        var actionListener:ActionListener=ActionListener{
                override public function actionPerformed(e:ActionEvent):Void{
                    lock=true;
                    checked=menuItem.getState();
                    lock=false;
                }
            };
        menuItem.addActionListener(actionListener);
        }
    }
